#include <iostream>
#include <thread>
#include <string>
//#include <pthread.h>

void function_1() {
    std::cout << "www.work" << std::endl;

}

class Factor
{
public:
    void operator()()
    {
        for (size_t i = 0; i < 10; i++)
        {
            std::cout << "from t1:" << i << std::endl;
        }
        
    }
};



int main() {
    //std::thread t1(function_1);  //t1线程开始运行

    //Factor fct;
    //std::thread t1(fct);  //使用对象
    std::thread t1((Factor()));  //直接使用类
    try {
        for (int i = 0; i < 10; i++)
        {
            std::cout << "from main:" << i << std::endl;
        }
    }
    catch (...){
        t1.join();
        throw;
    }

    t1.join();  //保证t1线程执行完主线程再退出
    std::cout << "666";
    return 0;
}